class EventEmitter {
  constructor() {
    this.events = {};
  }
  emit(name) {
    this.events[name] && this.events[name].forEach((cb) => cb());
  }
  on(name, cb) {
    this.events[name] = this.events[name] || [];
    this.events[name].push(cb);
  }
}

const emitter = new EventEmitter();
emitter.on("click", () => console.log("点击了"));
emitter.on("click", () => console.log("点击了2"));
emitter.emit("click");
